<template>
	<view>
		<view class="uni-padding-wrap">
			<uni-section title="请填写" type="line">
				<view class="example">
					<!-- 基础用法，不包含校验规则 -->
					<uni-forms ref="baseForm" :rules="rules" :model="baseFormData" labelWidth="80px">
						<uni-forms-item label="姓名" required name="xm">
							<uni-easyinput v-model="baseFormData.xm" placeholder="姓名" />
						</uni-forms-item>
						<uni-forms-item label="专业" required name="zy">
							<uni-easyinput v-model="baseFormData.zy" placeholder="专业" />
						</uni-forms-item>
						<uni-forms-item label="班级" required name="bj">
							<uni-easyinput v-model="baseFormData.bj" placeholder="班级" />
						</uni-forms-item>
					</uni-forms>
					<button type="primary" @click="submit('baseForm')">提交</button>
				</view>
			</uni-section>
		</view>
	</view>
</template>


<script>
	var _this;
	var vk = uni.vk;
	import uniForms from "@/pages_bd/components/uni-forms/uni-forms";
	import uniFormsItem from "@/pages_bd/components/uni-forms-item/uni-forms-item";
	export default {
		components:{uniForms,uniFormsItem},
		data() {
			// 页面数据变量
			return {
				options:{},
				baseFormData:{},
				// 校验规则
				rules: {
					xm: {
						rules: [{
							required: true,
							errorMessage: '姓名'
						}]
					},
					zy: {
						rules: [{
							required: true,
							errorMessage: '专业'
						}]
					},
					bj: {
						rules: [{
							required: true,
							errorMessage: '班级'
						}]
					}
				}
			}
		},
		// 监听 - 页面每次【加载时】执行(如：前进) await
		async onLoad(options = {}) {
			_this = this;
			vk = uni.vk;
			this.options = options;
			//this.init(options);
			let uuu = vk.getVuex("$user.stxxws");
			if(uuu){
				this.baseFormData = uuu;
			}
			console.log(uuu)
			
		},
		// 监听 - 页面【首次渲染完成时】执行。注意如果渲染速度快，会在页面进入动画完成前触发
		onReady(){
			
		},
		// 监听 - 页面每次【显示时】执行(如：前进和返回) (页面每次出现在屏幕上都触发，包括从下级页面点返回露出当前页面)
		onShow() {
			
		},
		// 监听 - 页面每次【隐藏时】执行(如：返回)
		onHide() {
			
		},
		// 监听 - 点击右上角转发时
		onShareAppMessage(options) {
			
		},
		// 函数
		methods: {
			submit(ref) {
				//console.log(this.baseFormData);
				this.$refs[ref].validate().then(res => {
					//console.log('success', res);
					vk.setVuex("$user.stxxws",this.baseFormData);
					uni.showToast({
						title: `设置成功`,icon:'none'
					})
				}).catch(err => {
					console.log('err', err);
				})
			},
			// 页面数据初始化函数
			init(options){
				//vk.reLaunch("/pages_template/uni-id/index/index");
			},
			pageTo(path){
				vk.navigateTo(path);
			}
		},
		// 监听器
		watch:{
			
		},
		// 计算属性
		computed:{
			
		}
	}
</script>
<style lang="scss" scoped>
	
	
</style>